﻿
@{
    Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<style>
	.layui-form-item {
		margin-bottom: 30px; /* 每个行之间的距离 */
		width: 450px
	}

	.layui-form-label {
		width: 160px
	}

	.layui-input-block {
		margin-left: 200px;
		width: 200px;
	}
</style>
<form class="layui-form" action="" style="margin-top:20px">
	<input type="hidden" name="Id" id="Id" />
	<table>
		<tr>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">通知单号</label>
					<div class="layui-input-block">
						<input type="text" id="NotificationNumber" name="NotificationNumber" lay-verify="required" placeholder="请输入通知单号" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">客户编码</label>
					<div class="layui-input-block">
						<input type="text" id="CustomerCode" name="CustomerCode" lay-verify="required" placeholder="请输入客户编码" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
		</tr>

		<tr>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">客户名称</label>
					<div class="layui-input-block">
						<input type="text" id="CustomerName" name="CustomerName" lay-verify="required" placeholder="请输入客户名称" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">通知单状态</label>
					<div class="layui-input-block">
						<input type="radio" id="NotificationStatus" name="NotificationStatus" value="true" title="计划中" checked>
						<input type="radio" id="NotificationStatus" name="NotificationStatus" value="false" title="已完成">
					</div>
				</div>
			</td>
		</tr>

		<tr>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">商品编码</label>
					<div class="layui-input-block">
						<input type="text" id="ProductCode" name="ProductCode" lay-verify="required" placeholder="请输入商品编码" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">商品名称</label>
					<div class="layui-input-block">
						<input type="text" id="ProductName" name="ProductName" lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
		</tr>

		<tr>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">通知单数量</label>
					<div class="layui-input-block">
						<input type="text" id="NotificationQuantity" name="NotificationQuantity" lay-verify="required" placeholder="请输入通知单数量" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">验收数量</label>
					<div class="layui-input-block">
						<input type="text" id="AcceptanceQuantity" name="AcceptanceQuantity" lay-verify="required" placeholder="请输入验收数量" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
		</tr>

		<tr>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">单位</label>
					<div class="layui-input-block">
						<input type="text" id="Unit" name="Unit" lay-verify="required" placeholder="请输入单位" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">体积CM3</label>
					<div class="layui-input-block">
						<input type="text" id="Volume" name="Volume" lay-verify="required" placeholder="请输入体积CM3" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
		</tr>

		<tr>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">重量KG</label>
					<div class="layui-input-block">
						<input type="text" id="Weight" name="Weight" lay-verify="required" placeholder="请输入重量KG" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">客户订单号</label>
					<div class="layui-input-block">
						<input type="text" id="CustomerOrderNumber" name="CustomerOrderNumber" lay-verify="required" placeholder="请输入客户订单号" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
		</tr>

		<tr>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">基本单位数量</label>
					<div class="layui-input-block">
						<input type="text" id="BasicUnitQuantity" name="BasicUnitQuantity" lay-verify="required" placeholder="请输入基本单位数量" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">基本单位</label>
					<div class="layui-input-block">
						<input type="text" id="BasicUnit" name="BasicUnit" lay-verify="required" placeholder="请输入基本单位" autocomplete="off" class="layui-input">
					</div>
				</div>
			</td>
		</tr>

		<tr>
			<td>
				<div class="layui-form-item">
					<label class="layui-form-label">生产日期</label>
					<div class="layui-input-inline layui-input-wrap">
						<input type="text" id="roductionDate" name="roductionDate" placeholder="yyyy-MM-dd" class="layui-input">
					</div>
				</div>
			</td>
		</tr>
	</table>
	<table style="margin-bottom:50px">
		<div style="margin-left:400px;margin-top:30px">
			<button type="submit" class="layui-btn" lay-submit lay-filter="add">立即提交</button>

			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</table>
</form>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui/layui.js"></script>
<script>
	$(function () {
		getPurchaseById()
	})
	
	function getPurchaseById() {
		$.ajax({
			url: "/PurchaseNoticeDetail/FanTianPurchaseDetail",
			data: { id: @ViewBag.id},
			type: "get",
			datatype: "json",
			success: function (res) {
				
				$("#Id").val(res.data.id);
				$("#NotificationNumber").val(res.data.notificationNumber);
				$("#CustomerCode").val(res.data.customerCode);
				$("#CustomerName").val(res.data.customerName);
				$("[name='NotificationStatus'][value="+res.data.notificationStatus+"]").prop("checked",true);
				$("#ProductCode").val(res.data.productCode);
				$("#ProductName").val(res.data.productName);
				$("#NotificationQuantity").val(res.data.notificationQuantity);
				$("#AcceptanceQuantity").val(res.data.acceptanceQuantity);
				$("#Unit").val(res.data.unit);
				$("#Volume").val(res.data.volume);
				$("#Weight").val(res.data.weight);
				$("#CustomerOrderNumber").val(res.data.customerOrderNumber);
				$("#BasicUnitQuantity").val(res.data.basicUnitQuantity);
				$("#BasicUnit").val(res.data.basicUnit);
				$("#roductionDate").val(res.data.roductionDate);

				layui.form.render("radio")
				layui.form.render("select")
			}
		})
	}

	layui.use(['form', 'layer', 'laydate'], function () {
		var form = layui.form;
		var layer = layui.layer;
		var laydate=layui.laydate;

		laydate.render({
			elem:'#roductionDate'
		})

		form.on('submit(add)', function (data) {
			var field = data.field; // 获取表单字段值

			// 此处可执行 Ajax 等操作
			$.ajax({
				url:"/PurchaseNoticeDetail/UpdatePurchaseNotice",
				type:"post",
				async:true,
				data: field,
				datatype: "json",
				success: function (res) {
					console.log(res)
					if (res.code == 1) {
						layer.alert('修改成功', { title: '操作结果' }, function () {
							var index = parent.layer.getFrameIndex(window.name); // 获取当前 iframe 层的索引
							parent.layer.close(index); // 关闭当前 iframe 层
							parent.location.reload(); // 刷新父页面
						});
					}
					else{
						layer.alert('修改失败', { title: '操作结果' });
					}
				}
			});
			return false; // 阻止默认 form 跳转
		})
	})
</script>